<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/2/9
 * Time: 下午1:56
 */

namespace app\web\controller;

use app\src\order\logic\OrdersPaycodeLogic;
use app\src\wxpay\action\WxPayJsAction;
use app\src\wxpay\action\WxPayJsNotifyAction;

class wxpay extends Weixin
{
    //跳转支付
    public function jump2pay(){
        $pay_code = $this->_param('order_code');
        $seller_name = $this->_param('seller_name');
        $price = $this->_param('price');

        $this->assignTitle('微信支付');
        $WxPayJsAction = new WxPayJsAction();

        $name = $pay_code;
        $code = $pay_code;
        $price = (float)$price / 100;
        if($price <= 0) $this->error($price);
        try{
            $jsApiParameters = $WxPayJsAction->buildPay($name, $code, $price);
        }catch (\Exception $e){
                $this->error('支付已过期','repair/order');
        }

        $this->assign('jsApiParameters', $jsApiParameters);
        $this->assign('seller_name', $seller_name);
        $this->assign('price', $price.'元');
        $this->assign('from', 'repair');
        return $this->fetch();
    }

    public function wxnotify(){
        $GLOBALS['HTTP_RAW_POST_DATA'] = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
        $WxPayJsNotifyAction = new WxPayJsNotifyAction();
        $WxPayJsNotifyAction->Handle(false);


    }

    public function paysuccess(){
        $this->assignTitle('支付成功');
        $this->userinfo = session("global_user");
        $openid=$this->userinfo['info']['openid'];
        $price = $this->_param('price');
        $seller_name= $this->_param('seller_name');
        $this->sendXF($openid,$price,$seller_name);
         //   $this->success('支付成功', url('wxpay/evaluate'));
        return $this->fetch();
    }

    public function evaluate(){

        return $this->fetch();

    }
}